package util;

import java.util.ArrayList;
import java.util.Random;

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math3.fitting.GaussianFitter;
import org.apache.commons.math3.fitting.PolynomialFitter;
import org.apache.commons.math3.optim.nonlinear.vector.MultivariateVectorOptimizer;
import org.apache.commons.math3.optim.nonlinear.vector.jacobian.LevenbergMarquardtOptimizer;

import common.Static;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		GaussianFitter fitter = new GaussianFitter(
				new LevenbergMarquardtOptimizer());
		Random rand = new Random();
		ArrayList<double[]> tests = MyUtil.getTestsForMathLogScale(1, 50, 8);
		for (int i = 0; i < tests.size(); i++) {
			double x = tests.get(i)[0];
			System.out.println(Math.log(x));
			double y = 50 * Math
					.exp(-(Math.log(x) - 2) * (Math.log(x) - 2) / 1);
			fitter.addObservedPoint(Math.log(x), y);
		}

		final double[] best = fitter.fit();

		for (int i = 0; i < best.length; i++) {
			System.out.println(best[i]);
		}
	}
}